<?php

/*
 * CopyRight  : (C)2012-2099 HaoTeam Inc.
 * Document   : AdminConfig.php
 * Created on : 2022-5-12 14:27:26
 * Author     : Tiger <1192851302@qq.com>
 * Description: This is NOT a freeware, use is subject to license terms.
 *              这即使是一个免费软件,使用时也请遵守许可证条款,得到当时人书面许可.
 *              未经书面许可,不得翻版,翻版必究;版权归属 HaoTeam Inc;
 */

namespace app\models;

use think\Model;

/**
 * 
 * Class AdminConfig
 * Tiger <1192851302@qq.com> 2022-5-12 14:27:26
 */
class AdminConfig extends Model {

    /**
     * 获取单个参数配置
     * @authr Tiger <1192851302@qq.com>
     * @param $key
     * @return bool|mixed
     */
    public static function getOne($key) {
        if (empty($key) || !($config_one = self::where('name', $key)->find())) {
            return false;
        }
        return json_decode($config_one['value'], true);
    }

    /**
     * 获得多个参数
     * @authr Tiger <1192851302@qq.com>
     * @param $keys
     * @return array
     */
    public static function getMore(array $keys) {
        $list = self::whereIn('name', $keys)->column('value', 'name') ?: [];
        foreach ($list as $key => $value) {
            $list[$key] = json_decode($value, true);
        }
        return $list;
    }

    /**
     * 获得多个参数
     * @authr Tiger <1192851302@qq.com>
     * @param int $tab_id 
     * @return array
     */
    public static function getAll(int $tab_id) {
        $list = self::where('tab_id', $tab_id)->column('value', 'name') ?: [];
        foreach ($list as $key => $value) {
            $list[$key] = json_decode($value, true);
        }
        return $list;
    }

}
